#include "lua_myclass_auto.hpp"
#include "HelloWorldScene.h"
#include "tolua_fix.h"
#include "LuaBasicConversions.h"


int lua_myclass_HelloWorld_init(lua_State* tolua_S)
{
    int argc = 0;
    HelloWorld* cobj = nullptr;
    bool ok  = true;

#if COCOS2D_DEBUG >= 1
    tolua_Error tolua_err;
#endif


#if COCOS2D_DEBUG >= 1
    if (!tolua_isusertype(tolua_S,1,"HelloWorld",0,&tolua_err)) goto tolua_lerror;
#endif

    cobj = (HelloWorld*)tolua_tousertype(tolua_S,1,0);

#if COCOS2D_DEBUG >= 1
    if (!cobj) 
    {
        tolua_error(tolua_S,"invalid 'cobj' in function 'lua_myclass_HelloWorld_init'", nullptr);
        return 0;
    }
#endif

    argc = lua_gettop(tolua_S)-1;
    if (argc == 0) 
    {
        if(!ok)
        {
            tolua_error(tolua_S,"invalid arguments in function 'lua_myclass_HelloWorld_init'", nullptr);
            return 0;
        }
        bool ret = cobj->init();
        tolua_pushboolean(tolua_S,(bool)ret);
        return 1;
    }
    luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "HelloWorld:init",argc, 0);
    return 0;

#if COCOS2D_DEBUG >= 1
    tolua_lerror:
    tolua_error(tolua_S,"#ferror in function 'lua_myclass_HelloWorld_init'.",&tolua_err);
#endif

    return 0;
}
int lua_myclass_HelloWorld_create(lua_State* tolua_S)
{
    int argc = 0;
    bool ok  = true;

#if COCOS2D_DEBUG >= 1
    tolua_Error tolua_err;
#endif

#if COCOS2D_DEBUG >= 1
    if (!tolua_isusertable(tolua_S,1,"HelloWorld",0,&tolua_err)) goto tolua_lerror;
#endif

    argc = lua_gettop(tolua_S) - 1;

    if (argc == 0)
    {
        if(!ok)
        {
            tolua_error(tolua_S,"invalid arguments in function 'lua_myclass_HelloWorld_create'", nullptr);
            return 0;
        }
        HelloWorld* ret = HelloWorld::create();
        object_to_luaval<HelloWorld>(tolua_S, "HelloWorld",(HelloWorld*)ret);
        return 1;
    }
    luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", "HelloWorld:create",argc, 0);
    return 0;
#if COCOS2D_DEBUG >= 1
    tolua_lerror:
    tolua_error(tolua_S,"#ferror in function 'lua_myclass_HelloWorld_create'.",&tolua_err);
#endif
    return 0;
}
int lua_myclass_HelloWorld_createScene(lua_State* tolua_S)
{
    int argc = 0;
    bool ok  = true;

#if COCOS2D_DEBUG >= 1
    tolua_Error tolua_err;
#endif

#if COCOS2D_DEBUG >= 1
    if (!tolua_isusertable(tolua_S,1,"HelloWorld",0,&tolua_err)) goto tolua_lerror;
#endif

    argc = lua_gettop(tolua_S) - 1;

    if (argc == 0)
    {
        if(!ok)
        {
            tolua_error(tolua_S,"invalid arguments in function 'lua_myclass_HelloWorld_createScene'", nullptr);
            return 0;
        }
        cocos2d::Scene* ret = HelloWorld::createScene();
        object_to_luaval<cocos2d::Scene>(tolua_S, "cc.Scene",(cocos2d::Scene*)ret);
        return 1;
    }
    luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", "HelloWorld:createScene",argc, 0);
    return 0;
#if COCOS2D_DEBUG >= 1
    tolua_lerror:
    tolua_error(tolua_S,"#ferror in function 'lua_myclass_HelloWorld_createScene'.",&tolua_err);
#endif
    return 0;
}
static int lua_myclass_HelloWorld_finalize(lua_State* tolua_S)
{
    printf("luabindings: finalizing LUA object (HelloWorld)");
    return 0;
}

int lua_register_myclass_HelloWorld(lua_State* tolua_S)
{
    tolua_usertype(tolua_S,"HelloWorld");
    tolua_cclass(tolua_S,"HelloWorld","HelloWorld","cc.Layer",nullptr);

    tolua_beginmodule(tolua_S,"HelloWorld");
        tolua_function(tolua_S,"init",lua_myclass_HelloWorld_init);
        tolua_function(tolua_S,"create", lua_myclass_HelloWorld_create);
        tolua_function(tolua_S,"createScene", lua_myclass_HelloWorld_createScene);
    tolua_endmodule(tolua_S);
    std::string typeName = typeid(HelloWorld).name();
    g_luaType[typeName] = "HelloWorld";
    g_typeCast["HelloWorld"] = "HelloWorld";
    return 1;
}
TOLUA_API int register_all_myclass(lua_State* tolua_S)
{
	tolua_open(tolua_S);
	
	tolua_module(tolua_S,nullptr,0);
	tolua_beginmodule(tolua_S,nullptr);

	lua_register_myclass_HelloWorld(tolua_S);

	tolua_endmodule(tolua_S);
	return 1;
}

